package cn.dengta.webapp.user.model;

import cn.dengta.common.model.ValueProxy;
import cn.dengta.common.model.ValueProxyImpl;
import cn.dengta.common.util.Common;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.Getter;
import me.codeplayer.util.Cmp;

@Getter
public enum LoveTreeLevel implements ValueProxyImpl<LoveTreeLevel, Integer> {
	L1(1, 2),
	L2(2, 8),
	L3(3, 30),
	L4(4, 120),
	L5(5, 250),
	L6(6, 500),
	L7(7, 1000),
	L8(8, 2500),
	;
	@EnumValue
	public final Integer value;
	final Integer maxValue;
	final String label;
	/** 礼物id */
	public Long giftId;
	/** 礼物图片路径 */
	public String giftIcon;

	final ValueProxy<LoveTreeLevel, Integer> proxy;

	LoveTreeLevel(Integer value, Integer maxValue) {
		this.value = value;
		this.label = name();
		this.maxValue = maxValue;
		this.proxy = new ValueProxy<>(this, value, label);
	}

	public static LoveTreeLevel of(Integer value) {
		return Common.getEnum(values(), LoveTreeLevel::getValue, value);
	}

	public boolean isLast(Integer maxValue) {
		return this == L8 && Cmp.eq(L8.maxValue, maxValue);
	}

	@Override
	public String toString() {
		JSONObject json = new JSONObject();
		json.put("value", value);
		json.put("maxValue", maxValue);
		json.put("label", label);
		json.put("giftId", giftId);
		json.put("giftIcon", giftIcon);
		return json.toJSONString();
	}
}
